package com.zzxx.wechat.adpater;

import cn.hutool.core.collection.CollectionUtil;
import com.zzxx.wechat.common.vo.ArcteryxColourVo;
import com.zzxx.wechat.common.vo.ArcteryxSkuVo;
import com.zzxx.wechat.entity.ArcteryxSku;
import org.springframework.beans.BeanUtils;

import java.util.*;

public class ArcteryxSkuAdapter {

    public static final Map<String, Integer> ARCTERYX_SKU_SIZE_MAP = new HashMap<>();

    static {
        ARCTERYX_SKU_SIZE_MAP.put("XXS", 1);
        ARCTERYX_SKU_SIZE_MAP.put("XS", 2);
        ARCTERYX_SKU_SIZE_MAP.put("S", 3);
        ARCTERYX_SKU_SIZE_MAP.put("M", 4);
        ARCTERYX_SKU_SIZE_MAP.put("L", 5);
        ARCTERYX_SKU_SIZE_MAP.put("XL", 6);
        ARCTERYX_SKU_SIZE_MAP.put("XXL", 7);
    }

    public static ArcteryxColourVo arcteryxSkuVo2ColourVo(List<ArcteryxSkuVo> arcteryxSkuVoList) {
        //  arcteryxSkuList.sort(Comparator.comparingInt(c -> ArcteryxSkuAdapter.ARCTERYX_SKU_SIZE_MAP.get(c.getSizeLabel())));

        ArcteryxColourVo arcteryxColourVo = new ArcteryxColourVo();
        ArcteryxSkuVo basicArcteryxVoSku = arcteryxSkuVoList.get(0);
        arcteryxColourVo.setColourLabel(basicArcteryxVoSku.getColourLabel());
        arcteryxColourVo.setRealPrice(basicArcteryxVoSku.getDiscountPrice() == null ? String.valueOf(basicArcteryxVoSku.getPrice()) : String.valueOf(basicArcteryxVoSku.getDiscountPrice()));

        StringBuilder colourInventory = new StringBuilder();
        for (ArcteryxSkuVo arcteryxSku : arcteryxSkuVoList) {
            colourInventory.append(arcteryxSku.getSizeLabel()).append(":").append(arcteryxSku.getInventory()).append("|");
        }
        arcteryxColourVo.setColourInventory(colourInventory.toString());
        return arcteryxColourVo;
    }


    public static List<ArcteryxSkuVo> arcteryxSku2Vos(List<ArcteryxSku> arcteryxSkuList) {

        if (CollectionUtil.isEmpty(arcteryxSkuList)) {
            return Collections.emptyList();
        }
        List<ArcteryxSkuVo> arcteryxSkuVos = new ArrayList<>();

        for (ArcteryxSku arcteryxSku : arcteryxSkuList) {
            ArcteryxSkuVo arcteryxSkuVo = new ArcteryxSkuVo();
            BeanUtils.copyProperties(arcteryxSku, arcteryxSkuVo);
            arcteryxSkuVos.add(arcteryxSkuVo);
        }
        return arcteryxSkuVos;
    }

}
